const mysql = require('mysql2');
//引入mysql2内核
const config = require('./config');
//应用全局变量
const connections = mysql.createPool({
	host: config.MYSQL_HOST,
	port: config.MYSQL_PORT,
	database: config.MYSQL_DATABASE,
	user: config.MYSQL_USER,
	password: config.MYSQL_PASSWORD
});//创建MySQL连接池，键入数据库链接信息

connections.getConnection((err, conn) => {
	conn.connect((err)=>{
		if (err) {
			console.log("链接失败");
		}
		else{
			console.log("数据库链接成功");
		}
	})
});
//验证数据库是否链接成功

module.exports = connections.promise();
//把数据库链接模块异步导出至控制器service进行数据库的查询
